-
Notifications
You must be signed in to change notification settings - Fork 0
/
x.go
40 lines (36 loc) · 1.24 KB
/
x.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright 2015 The Vanadium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package xtest provides utilities for testing jiri functionality.
package xtest
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
"time"
"github.com/btwiuse/jiri"
"github.com/btwiuse/jiri/cmdline"
"github.com/btwiuse/jiri/color"
"github.com/btwiuse/jiri/log"
"github.com/btwiuse/jiri/tool"
)
// NewX is similar to jiri.NewX, but is meant for usage in a testing environment.
func NewX(t *testing.T) (*jiri.X, func()) {
ctx := tool.NewContextFromEnv(cmdline.EnvFromOS())
color := color.NewColor(color.ColorNever)
logger := log.NewLogger(log.InfoLevel, color, false, 0, time.Second*100, nil, nil)
root, err := ioutil.TempDir("", "")
if err != nil {
t.Fatalf("TempDir() failed: %v", err)
}
if err := os.Mkdir(filepath.Join(root, jiri.RootMetaDir), 0755); err != nil {
t.Fatalf("TempDir() failed: %v", err)
}
cleanup := func() {
if err := os.RemoveAll(root); err != nil {
t.Fatalf("RemoveAll(%q) failed: %v", root, err)
}
}
return &jiri.X{Context: ctx, Root: root, Jobs: jiri.DefaultJobs, Color: color, Logger: logger, Attempts: 1, LockfileEnabled: false}, cleanup
}