MCPcopy
hub / github.com/perkeep/perkeep / testStorage

Function testStorage

pkg/blobserver/google/cloudstorage/cloudstorage_test.go:71–210  ·  view source on GitHub ↗
(t *testing.T, bucketDir string)

Source from the content-addressed store, hash-verified

69}
70
71func testStorage(t *testing.T, bucketDir string) {
72 if *bucket == "" && *configFile == "" {
73 t.Skip("Skipping test without --bucket or --config flag")
74 }
75 var refreshToken string
76 if *configFile != "" {
77 data, err := os.ReadFile(*configFile)
78 if err != nil {
79 t.Fatalf("Error reading config file %v: %v", *configFile, err)
80 }
81 var conf Config
82 if err := json.Unmarshal(data, &conf); err != nil {
83 t.Fatalf("Error decoding config file %v: %v", *configFile, err)
84 }
85 *clientID = conf.Auth.ClientID
86 *clientSecret = conf.Auth.ClientSecret
87 refreshToken = conf.Auth.RefreshToken
88 *bucket = conf.Bucket
89 }
90 if *bucket == "" {
91 t.Fatal("bucket not provided in config file or as a flag.")
92 }
93 if *clientID == "" {
94 if *clientSecret == "" {
95 // Assume auto if neither the the clientID and clientSecret are specified
96 // A service account key should be specified using the GOOGLE_APPLICATION_CREDENTIALS environment variable.
97 *clientID = "auto"
98 } else {
99 t.Fatal("client ID and client secret must be specified together. Obtain from https://console.developers.google.com/ > Project > APIs & Auth > Credentials. Should be a 'native' or 'Installed application'")
100 }
101 }
102 if *configFile == "" {
103 config := &oauth2.Config{
104 Scopes: []string{storage.ScopeReadWrite},
105 Endpoint: google.Endpoint,
106 ClientID: *clientID,
107 ClientSecret: *clientSecret,
108 RedirectURL: oauthutil.TitleBarRedirectURL,
109 }
110 if !metadata.OnGCE() && *clientID != "auto" {
111 token, err := oauth2.ReuseTokenSource(nil,
112 &oauthutil.TokenSource{
113 Config: config,
114 CacheFile: *tokenCache,
115 AuthCode: func() string {
116 if *authCode == "" {
117 t.Skipf("Re-run using --auth_code= with the value obtained from %s",
118 config.AuthCodeURL("", oauth2.AccessTypeOffline, oauth2.ApprovalForce))
119 return ""
120 }
121 return *authCode
122 },
123 }).Token()
124 if err != nil {
125 t.Fatalf("could not acquire token: %v", err)
126 }
127 refreshToken = token.RefreshToken
128 }

Callers 2

TestStorageFunction · 0.70
TestStorageWithBucketDirFunction · 0.70

Calls 11

TestOptFunction · 0.92
EnumerateAllFunction · 0.92
FatalMethod · 0.80
PrintfMethod · 0.80
LogfMethod · 0.80
newFromConfigFunction · 0.70
FatalfMethod · 0.65
NextMethod · 0.65
CloseMethod · 0.65
RemoveBlobsMethod · 0.65
DeleteMethod · 0.65

Tested by

no test coverage detected