-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Allow reading config from env vars (#152)
- Loading branch information
1 parent
7081e88
commit 4b7f669
Showing
9 changed files
with
102 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package conf | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestReadClientConfig(t *testing.T) { | ||
type args struct { | ||
path string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want *ClientConf | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "happy path", | ||
args: args{"../contrib/client.json"}, | ||
want: &ClientConf{ | ||
Host: "my.host.tld", | ||
KeyPairPath: "/keypair.json", | ||
MetricsListener: ":9191", | ||
MqttConfig: MqttConfig{ | ||
Brokers: []string{"broker-1", "broker-2"}, | ||
ClientId: "my-client-id", | ||
}, | ||
}, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "non-existing-file", | ||
args: args{"some-file"}, | ||
want: nil, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "wrong format", | ||
args: args{"../contrib/textfile.txt"}, | ||
want: nil, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "empty json file content", | ||
args: args{"../contrib/empty.json"}, | ||
want: getDefaultClientConfig(), | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "empty path", | ||
args: args{""}, | ||
want: &ClientConf{}, | ||
wantErr: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := ReadClientConfig(tt.args.path) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("ReadClientConfig() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("ReadClientConfig() got = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"host": "my.host.tld", | ||
"keypair_path": "/keypair.json", | ||
"client_id": "my-client-id", | ||
"brokers": ["broker-1", "broker-2"] | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
no json here |
This file contains 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
This file contains 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