-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
store: azure: allow passing an endpoint parameter for specific regions
Fix #968 Signed-off-by: Adrien Fillon <[email protected]>
- Loading branch information
Showing
5 changed files
with
178 additions
and
28 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,87 @@ | ||
package azure | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/improbable-eng/thanos/pkg/testutil" | ||
) | ||
|
||
func TestConfig_validate(t *testing.T) { | ||
type fields struct { | ||
StorageAccountName string | ||
StorageAccountKey string | ||
ContainerName string | ||
Endpoint string | ||
} | ||
tests := []struct { | ||
name string | ||
fields fields | ||
wantErr bool | ||
wantEndpoint string | ||
}{ | ||
{ | ||
name: "valid global configuration", | ||
fields: fields{ | ||
StorageAccountName: "foo", | ||
StorageAccountKey: "bar", | ||
ContainerName: "roo", | ||
}, | ||
wantErr: false, | ||
wantEndpoint: azureDefaultEndpoint, | ||
}, | ||
{ | ||
name: "valid custom endpoint", | ||
fields: fields{ | ||
StorageAccountName: "foo", | ||
StorageAccountKey: "bar", | ||
ContainerName: "roo", | ||
Endpoint: "blob.core.chinacloudapi.cn", | ||
}, | ||
wantErr: false, | ||
wantEndpoint: "blob.core.chinacloudapi.cn", | ||
}, | ||
{ | ||
name: "no account key but account name", | ||
fields: fields{ | ||
StorageAccountName: "foo", | ||
StorageAccountKey: "", | ||
ContainerName: "roo", | ||
}, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "no account name but account key", | ||
fields: fields{ | ||
StorageAccountName: "", | ||
StorageAccountKey: "bar", | ||
ContainerName: "roo", | ||
}, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "no container name", | ||
fields: fields{ | ||
StorageAccountName: "foo", | ||
StorageAccountKey: "bar", | ||
ContainerName: "", | ||
}, | ||
wantErr: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
conf := &Config{ | ||
StorageAccountName: tt.fields.StorageAccountName, | ||
StorageAccountKey: tt.fields.StorageAccountKey, | ||
ContainerName: tt.fields.ContainerName, | ||
Endpoint: tt.fields.Endpoint, | ||
} | ||
err := conf.validate() | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("Config.validate() error = %v, wantErr %v", err, tt.wantErr) | ||
} else { | ||
testutil.Equals(t, tt.wantEndpoint, conf.Endpoint) | ||
} | ||
}) | ||
} | ||
} |
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,56 @@ | ||
package azure | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/improbable-eng/thanos/pkg/testutil" | ||
) | ||
|
||
func Test_getContainerURL(t *testing.T) { | ||
type args struct { | ||
conf Config | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want string | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "default", | ||
args: args{ | ||
conf: Config{ | ||
StorageAccountName: "foo", | ||
StorageAccountKey: "Zm9vCg==", | ||
ContainerName: "roo", | ||
Endpoint: azureDefaultEndpoint, | ||
}, | ||
}, | ||
want: "https://foo.blob.core.windows.net/roo", | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "azure china", | ||
args: args{ | ||
conf: Config{ | ||
StorageAccountName: "foo", | ||
StorageAccountKey: "Zm9vCg==", | ||
ContainerName: "roo", | ||
Endpoint: "blob.core.chinacloudapi.cn", | ||
}, | ||
}, | ||
want: "https://foo.blob.core.chinacloudapi.cn/roo", | ||
wantErr: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := getContainerURL(tt.args.conf) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("getContainerURL() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
testutil.Equals(t, tt.want, got.String()) | ||
}) | ||
} | ||
} |