-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathproject_name_test.go
More file actions
63 lines (54 loc) · 1.36 KB
/
project_name_test.go
File metadata and controls
63 lines (54 loc) · 1.36 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
package projectname
import (
"context"
"testing"
"github.com/google/uuid"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/stackitcloud/stackit-cli/internal/pkg/testparams"
"github.com/stackitcloud/stackit-cli/internal/pkg/config"
)
var testProjectId = uuid.NewString()
func TestGetProjectName(t *testing.T) {
tests := []struct {
description string
projectName string
projectId string
isValid bool
}{
{
description: "Project name from config",
projectName: "project-name",
projectId: testProjectId,
isValid: true,
},
{
description: "empty project name and id",
projectName: "",
projectId: "",
isValid: false,
},
}
for _, tt := range tests {
t.Run(tt.description, func(t *testing.T) {
viper.Set(config.ProjectNameKey, tt.projectName)
viper.Set(config.ProjectIdKey, tt.projectId)
defer viper.Reset()
params := testparams.NewTestParams()
cmd := &cobra.Command{}
projectName, err := GetProjectName(context.Background(), params.Printer, "0.0.0-dummy", cmd)
if err != nil {
if tt.isValid {
t.Fatalf("unexpected error: %v", err)
}
return
}
if !tt.isValid {
t.Fatalf("expected error, got project name %q", projectName)
}
if projectName != tt.projectName {
t.Fatalf("expected project name %q, got %q", tt.projectName, projectName)
}
})
}
}