This repository was archived by the owner on Apr 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathadd_test.go
More file actions
73 lines (60 loc) · 1.73 KB
/
Copy pathadd_test.go
File metadata and controls
73 lines (60 loc) · 1.73 KB
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
package main
import (
"io/ioutil"
"os"
"path"
"testing"
"github.com/simplyserenity/kitkit/config"
"github.com/mitchellh/cli"
)
// kitkit add [relative path to binary file] --name(-n)=[binary's default name] --tag(-t)=[string for the tag(version)]
// the binary's name is what kitkit will list it as and add it to the path as
// the tag is how the separate versions of the binary will be tracked (similar to docker tags)
func TestAddCommand_Run(t *testing.T) {
testDir, cleanup := testKitKitDirectory(t)
defer cleanup()
ui := new(cli.MockUi)
c := &AddCommand{
Ui: ui,
}
args := []string{
"testdata/testBinary",
"-name=test-binary",
"-tag=1.0",
}
if returnCode := c.Run(args); returnCode != 0 {
t.Fatalf("bad return code: %d\n\n%s", returnCode, ui.ErrorWriter.String())
}
want := "binaries/test-binary-kktag:1.0"
// check if the file was copied and tagged
if _, err := os.Stat(path.Join(testDir, want)); err != nil {
t.Fatalf("couldn't find the copied binary file: %s", want)
}
}
// creates the testing directory
// sets KITKIT_HOME to the testing directory
// returns the testdir and a function that will unset the env and delete the testing directory
func testKitKitDirectory(t *testing.T) (string, func()) {
oldHome := os.Getenv("KITKIT_HOME")
dir, err := ioutil.TempDir("testdata", "kitkit")
if err != nil {
t.Fatalf("failed to create tempdir: %s", err)
}
err = os.Setenv("KITKIT_HOME", dir)
if err != nil {
t.Fatal(err)
}
if err = config.KitkitSetup(); err != nil {
t.Fatal(err)
}
return dir, func() {
err = os.Setenv("KITKIT_HOME", oldHome)
if err != nil {
t.Fatal(err)
}
err = os.RemoveAll(dir)
if err != nil {
t.Fatalf("failed to remove the testdata/kitkit directory: %s", err)
}
}
}