blob: add4d896e1860eaae4db460a7ae9996aea7ecdd9 [file] [log] [blame]
// Copyright 2017 The LUCI Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package main
import (
"context"
"io/ioutil"
"os"
"path/filepath"
"runtime"
"testing"
"github.com/maruel/subcommands"
"go.chromium.org/luci/mmutex/lib"
. "github.com/smartystreets/goconvey/convey"
)
func TestShared(t *testing.T) {
Convey("RunShared", t, func() {
lockFileDir, err := ioutil.TempDir("", "")
So(err, ShouldBeNil)
defer os.Remove(lockFileDir)
env := subcommands.Env{
lib.LockFileEnvVariable: subcommands.EnvVar{
Value: lockFileDir,
Exists: true,
},
}
Convey("executes the command", func() {
tempDir, err := ioutil.TempDir("", "")
So(err, ShouldBeNil)
defer os.Remove(tempDir)
testFilePath := filepath.Join(tempDir, "test")
var command []string
if runtime.GOOS == "windows" {
command = createCommand([]string{"copy", "NUL", testFilePath})
} else {
command = createCommand([]string{"touch", testFilePath})
}
So(RunShared(context.Background(), env, command), ShouldBeNil)
_, err = os.Stat(testFilePath)
So(err, ShouldBeNil)
})
})
}