-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclickonce_test.go
90 lines (76 loc) · 1.7 KB
/
clickonce_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Copyright 2020 Stefano Cotta Ramusino. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package clickonce
import (
"io/ioutil"
"log"
"os"
"path/filepath"
"testing"
)
const (
applicationUrl = "https://aka.ms/resxunusedfinder"
)
var subset = []string{"ResxUnusedFinder.exe"}
var co ClickOnce
func TestClickOnce_SetLogger(t *testing.T) {
logger := log.New(os.Stdout, "", log.LstdFlags)
co.SetLogger(logger)
}
func TestClickOnce_Init(t *testing.T) {
err := co.Init(applicationUrl)
if err != nil {
t.Error(err)
}
}
func TestClickOnce_GetAll(t *testing.T) {
err := co.GetAll()
if err != nil {
t.Error(err)
}
}
func TestClickOnce_DeployedFiles(t *testing.T) {
deployedFiles := co.DeployedFiles()
for _, subsetFileName := range subset {
if _, ok := deployedFiles[subsetFileName]; !ok {
t.Errorf("'%s' not found in DeployedFiles()", subsetFileName)
}
}
}
func TestClickOnce_Get(t *testing.T) {
tempOutputDir, err := ioutil.TempDir("", "clickonce_test_")
if err != nil {
t.Error("cannot create temporary directory for test")
}
defer func() {
err = os.RemoveAll(tempOutputDir)
if err != nil {
t.Error("cannot delete temporary directory used for test")
}
}()
co.SetOutputDir(tempOutputDir)
err = co.Get(subset)
if err != nil {
t.Error(err)
}
found := 0
err = filepath.Walk(tempOutputDir, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
for _, s := range subset {
if !info.IsDir() && info.Name() == s {
found += 1
return nil
}
}
return nil
})
if err != nil {
t.Error(err)
}
if found != len(subset) {
t.Error("missing downloaded files")
}
}