Skip to content

Commit 0e9d819

Browse files
bala-cegaccraw
authored andcommitted
Fixing tests & linting errors
Signed-off-by: Amanda Crawley <[email protected]>
1 parent 62952c0 commit 0e9d819

File tree

4 files changed

+39
-60
lines changed

4 files changed

+39
-60
lines changed

plugins/huggingface/huggingface-cli.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import (
99

1010
func HuggingFaceCLI() schema.Executable {
1111
return schema.Executable{
12-
Name: "HuggingFace CLI",
13-
Runs: []string{"huggingface-cli"},
14-
DocsURL: sdk.URL("https://huggingface.co/docs/huggingface_hub/quick-start"),
12+
Name: "HuggingFace CLI",
13+
Runs: []string{"huggingface-cli"},
14+
DocsURL: sdk.URL("https://huggingface.co/docs/huggingface_hub/quick-start"),
1515
NeedsAuth: needsauth.IfAll(
1616
needsauth.NotForHelpOrVersion(),
1717
needsauth.NotWithoutArgs(),
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hf_yVvZeburdKtnwkVCWPXimmNwaFuEXAMPLE

plugins/huggingface/user_access_token.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ import (
1414
func UserAccessToken() schema.CredentialType {
1515
return schema.CredentialType{
1616
Name: credname.APIToken,
17-
DocsURL: sdk.URL("https://huggingface.co/docs/hub/security-tokens"),
18-
ManagementURL: sdk.URL("https://huggingface.co/settings/tokens"),
17+
DocsURL: sdk.URL("https://huggingface.co/docs/hub/security-tokens"),
18+
ManagementURL: sdk.URL("https://huggingface.co/settings/tokens"),
1919
Fields: []schema.CredentialField{
2020
{
2121
Name: fieldname.UserAccessToken,
2222
MarkdownDescription: "Token used to authenticate to HuggingFace.",
2323
Secret: true,
2424
Composition: &schema.ValueComposition{
2525
Length: 37,
26-
Prefix: "hf_",
26+
Prefix: "hf_",
2727
Charset: schema.Charset{
2828
Uppercase: true,
2929
Lowercase: true,
@@ -64,16 +64,15 @@ func UserAccessToken() schema.CredentialType {
6464
Importer: importer.TryAll(
6565
importer.TryEnvVarPair(defaultEnvVarMapping),
6666
TryHuggingFaceTokenFile(),
67-
),}
67+
)}
6868
}
6969

7070
var defaultEnvVarMapping = map[string]sdk.FieldName{
71-
"HUGGING_FACE_HUB_TOKEN": fieldname.UserAccessToken,
72-
"HF_ENDPOINT": fieldname.Endpoint,
73-
"HF_INFERENCE_ENDPOINT": fieldname.APIUrl,
71+
"HUGGING_FACE_HUB_TOKEN": fieldname.UserAccessToken,
72+
"HF_ENDPOINT": fieldname.Endpoint,
73+
"HF_INFERENCE_ENDPOINT": fieldname.APIUrl,
7474
}
7575

76-
7776
func TryHuggingFaceTokenFile() sdk.Importer {
7877
return importer.TryFile("~/.cache/huggingface/token", func(ctx context.Context, contents importer.FileContents, in sdk.ImportInput, out *sdk.ImportAttempt) {
7978
fileData := string(contents)

plugins/huggingface/user_access_token_test.go

Lines changed: 28 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,68 +2,47 @@ package huggingface
22

33
import (
44
"testing"
5-
5+
66
"github.com/1Password/shell-plugins/sdk"
77
"github.com/1Password/shell-plugins/sdk/plugintest"
88
"github.com/1Password/shell-plugins/sdk/schema/fieldname"
99
)
10-
11-
func TestAPITokenProvisioner(t *testing.T) {
12-
plugintest.TestProvisioner(t, UserAccessToken().DefaultProvisioner, map[string]plugintest.ProvisionCase{
13-
"default": {
14-
ItemFields: map[sdk.FieldName]string{
15-
fieldname.UserAccessToken: "hf_yVvZeburdKtnwkVCWPXimmNwaFuEXAMPLE",
16-
fieldname.Endpoint: "https://huggingface.co",
17-
fieldname.APIUrl: "https://api-inference.huggingface.com",
18-
},
19-
ExpectedOutput: sdk.ProvisionOutput{
20-
Environment: map[string]string{
21-
"HUGGINGFACE_TOKEN": "hf_yVvZeburdKtnwkVCWPXimmNwaFuEXAMPLE",
22-
"HF_ENDPOINT": "https://huggingface.co",
23-
"HF_INFERENCE_ENDPOINT": "https://api-inference.huggingface.com",
2410

11+
func TestAPITokenProvisioner(t *testing.T) {
12+
plugintest.TestProvisioner(
13+
t, UserAccessToken().DefaultProvisioner, map[string]plugintest.ProvisionCase{
14+
"default": {
15+
ItemFields: map[sdk.FieldName]string{
16+
fieldname.UserAccessToken: "hf_yVvZeburdKtnwkVCWPXimmNwaFuEXAMPLE",
17+
fieldname.Endpoint: "https://huggingface.co",
18+
fieldname.APIUrl: "https://api-inference.huggingface.com",
19+
},
20+
ExpectedOutput: sdk.ProvisionOutput{
21+
Environment: map[string]string{
22+
"HUGGING_FACE_HUB_TOKEN": "hf_yVvZeburdKtnwkVCWPXimmNwaFuEXAMPLE",
23+
"HF_ENDPOINT": "https://huggingface.co",
24+
"HF_INFERENCE_ENDPOINT": "https://api-inference.huggingface.com",
25+
},
2526
},
2627
},
27-
},
28-
})
28+
})
2929
}
3030

3131
func TestAPITokenImporter(t *testing.T) {
32-
plugintest.TestImporter(t, UserAccessToken().Importer, map[string]plugintest.ImportCase{
33-
"environment": {
34-
Environment: map[string]string{
35-
"HUGGINGFACE_TOKEN": "hf_yVvZeburdKtnwkVCWPXimmNwaFuEXAMPLE",
36-
"HF_ENDPOINT": "https://huggingface.co",
37-
"HF_INFERENCE_ENDPOINT": "https://api-inference.huggingface.com",
38-
},
39-
ExpectedCandidates: []sdk.ImportCandidate{
40-
{
41-
Fields: map[sdk.FieldName]string{
42-
fieldname.UserAccessToken: "hf_yVvZeburdKtnwkVCWPXimmNwaFuEXAMPLE",
43-
fieldname.Endpoint: "https://huggingface.co",
44-
fieldname.APIUrl: "https://api-inference.huggingface.com",
45-
},
46-
},
47-
},
48-
},
49-
"token file": {
50-
Files: map[string]string{
51-
"~/.cache/huggingface/token": plugintest.LoadFixture(t, "token"),
52-
},
53-
ExpectedCandidates: []sdk.ImportCandidate{
54-
{
55-
NameHint: "[email protected]",
56-
Fields: map[sdk.FieldName]string{
57-
fieldname.UserAccessToken: "hf_yVvZeburdKtnwkVCWPXimmNwaFuEXAMPLE",
58-
},
32+
plugintest.TestImporter(
33+
t, UserAccessToken().Importer, map[string]plugintest.ImportCase{
34+
"config file (macOS)": {
35+
Files: map[string]string{
36+
"~/.cache/huggingface/token": plugintest.LoadFixture(t, "token"),
5937
},
60-
{
61-
NameHint: "[email protected]",
62-
Fields: map[sdk.FieldName]string{
63-
fieldname.UserAccessToken: "hf_yVvZeburdKtnwkVCWPXimmNwaFuEXAMPLE",
38+
ExpectedCandidates: []sdk.ImportCandidate{
39+
{
40+
Fields: map[sdk.FieldName]string{
41+
fieldname.UserAccessToken: "hf_yVvZeburdKtnwkVCWPXimmNwaFuEXAMPLE",
42+
},
6443
},
6544
},
6645
},
6746
},
68-
})
47+
)
6948
}

0 commit comments

Comments
 (0)