mirror of
https://github.com/drone-plugins/drone-npm.git
synced 2026-06-04 18:23:52 +08:00
8f610a8a9f
Use golang:1.18 for the build/test images. Fix all linter errors. Update go.mod to 1.16 to support os.ReadFile, os.WriteFile. Update libraries.
51 lines
1.6 KiB
Go
51 lines
1.6 KiB
Go
// Copyright (c) 2020, the Drone Plugins project authors.
|
|
// Please see the AUTHORS file for details. All rights reserved.
|
|
// Use of this source code is governed by an Apache 2.0 license that can be
|
|
// found in the LICENSE file.
|
|
|
|
package plugin
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestTokenRCContents(t *testing.T) {
|
|
settings := Settings{
|
|
Registry: "https://npm.someorg.com/",
|
|
Token: "token",
|
|
}
|
|
actual := npmrcContentsToken(&settings)
|
|
expected := "//npm.someorg.com/:_authToken=token"
|
|
if actual != expected {
|
|
t.Errorf("Unexpected token settings (Got: %s, Expected: %s)", actual, expected)
|
|
}
|
|
|
|
settings.Registry = "https://npm.someorg.com/with/path/"
|
|
actual = npmrcContentsToken(&settings)
|
|
expected = "//npm.someorg.com/with/path/:_authToken=token"
|
|
if actual != expected {
|
|
t.Errorf("Unexpected token settings (Got: %s, Expected: %s)", actual, expected)
|
|
}
|
|
|
|
settings.Registry = globalRegistry
|
|
actual = npmrcContentsToken(&settings)
|
|
expected = "//registry.npmjs.org/:_authToken=token"
|
|
if actual != expected {
|
|
t.Errorf("Unexpected token settings (Got: %s, Expected: %s)", actual, expected)
|
|
}
|
|
|
|
settings.Registry = "https://npm.someorg.com"
|
|
actual = npmrcContentsToken(&settings)
|
|
expected = "//npm.someorg.com/:_authToken=token"
|
|
if actual != expected {
|
|
t.Errorf("Unexpected token settings (Got: %s, Expected: %s)", actual, expected)
|
|
}
|
|
|
|
settings.Registry = "https://npm.someorg.com/with/path"
|
|
actual = npmrcContentsToken(&settings)
|
|
expected = "//npm.someorg.com/with/path/:_authToken=token"
|
|
if actual != expected {
|
|
t.Errorf("Unexpected token settings (Got: %s, Expected: %s)", actual, expected)
|
|
}
|
|
}
|