Created
July 9, 2020 12:59
-
-
Save refs/999c362c8435884b37e06669af0e0bc3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package store | |
import ( | |
"testing" | |
olog "github.com/owncloud/ocis-pkg/v2/log" | |
"github.com/owncloud/ocis-settings/pkg/proto/v0" | |
) | |
var scenarios = []struct { | |
name string | |
in struct { | |
record *proto.SettingsBundle | |
filePath string | |
} | |
out interface{} | |
}{ | |
{ | |
name: "generic-test", | |
in: struct { | |
record *proto.SettingsBundle | |
filePath string | |
}{ | |
record: &proto.SettingsBundle{ | |
DisplayName: "test1", | |
Identifier: &proto.Identifier{ | |
AccountUuid: "c4572da7-6142-4383-8fc6-efde3d463036", | |
Bundle: "test-bundle-1", | |
Extension: "test-extension-1", | |
Setting: "test-settings", | |
}, | |
Resource: &proto.Resource{ | |
Type: proto.Resource_FILE, | |
Values: []string{ | |
"beep", | |
"boop", | |
}, | |
}, | |
Settings: []*proto.Setting{ | |
{ | |
Description: "test-desc-1", | |
DisplayName: "test-displayname-1", | |
Name: "test-name-1", | |
Resource: &proto.Resource{ | |
Type: proto.Resource_FILE, | |
Values: []string{ | |
"bleep", | |
"blorg", | |
}, | |
}, | |
Value: &proto.Setting_IntValue{ | |
IntValue: &proto.IntSetting{ | |
Min: 0, | |
Max: 42, | |
}, | |
}, | |
}, | |
}, | |
}, | |
filePath: "/var/tmp/herecomesthesun", // TODO replace this with a testing temp file. | |
}, | |
out: nil, | |
}, | |
{ | |
name: "generic-test-2", | |
in: struct { | |
record *proto.SettingsBundle | |
filePath string | |
}{ | |
record: &proto.SettingsBundle{ | |
DisplayName: "test1", | |
Identifier: &proto.Identifier{ | |
AccountUuid: "c4572da7-6142-4383-8fc6-efde3d463034", | |
Bundle: "test-bundle-2", | |
Extension: "test-extension-2", | |
Setting: "test-settings", | |
}, | |
Resource: &proto.Resource{ | |
Type: proto.Resource_FILE, | |
Values: []string{ | |
"beep", | |
"boop", | |
}, | |
}, | |
Settings: []*proto.Setting{ | |
{ | |
Description: "test-desc-2", | |
DisplayName: "test-displayname-2", | |
Name: "test-name-2", | |
Resource: &proto.Resource{ | |
Type: proto.Resource_FILE, | |
Values: []string{ | |
"bleep", | |
"blorg", | |
}, | |
}, | |
Value: &proto.Setting_IntValue{ | |
IntValue: &proto.IntSetting{ | |
Min: 0, | |
Max: 42, | |
}, | |
}, | |
}, | |
}, | |
}, | |
filePath: "/var/tmp/herecomesthesun", // TODO replace this with a testing temp file. | |
}, | |
out: nil, | |
}, | |
} | |
func TestWriteRecordToFile(t *testing.T) { | |
s := Store{ | |
mountPath: "/var/tmp/herecomesthesun", | |
Logger: olog.NewLogger( | |
olog.Color(true), | |
olog.Pretty(true), | |
olog.Level("info"), | |
), | |
} | |
for i := range scenarios { | |
index := i | |
t.Run(scenarios[index].name, func(t *testing.T) { | |
t.Parallel() | |
filePath := s.buildFilePathFromBundle(scenarios[index].in.record, true) | |
if err := s.writeRecordToFile(scenarios[index].in.record, filePath); err != nil { | |
t.Error(err) | |
} | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment