<commit_before>// Copyright 2015 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.

package featuretests

import (
	"bufio"
	"io/ioutil"
	"time"

	"github.com/juju/loggo"
	"github.com/juju/names"
	jujutesting "github.com/juju/testing"
	jc "github.com/juju/testing/checkers"
	gc "gopkg.in/check.v1"
	"gopkg.in/mgo.v2/bson"

	"github.com/juju/juju/agent"
	"github.com/juju/juju/api"
	agentcmd "github.com/juju/juju/cmd/jujud/agent"
	agenttesting "github.com/juju/juju/cmd/jujud/agent/testing"
	"github.com/juju/juju/feature"
	"github.com/juju/juju/lease"
	"github.com/juju/juju/state"
	coretesting "github.com/juju/juju/testing"
	"github.com/juju/juju/testing/factory"
	"github.com/juju/juju/version"
	"github.com/juju/juju/worker/logsender"
	"github.com/juju/juju/worker/peergrouper"
)

// dblogSuite tests that logs flow correctly from the machine and unit
// agents over the API into MongoDB. These are very much integration
// tests with more detailed testing of the individual components
// being done in unit tests.
type dblogSuite struct {
	agenttesting.AgentSuite
}

func (s *dblogSuite) SetUpTest(c *gc.C) {
	s.SetInitialFeatureFlags("db-log")
	s.AgentSuite.SetUpTest(c)

	// Change the path to "juju-run", so that the
	// tests don't try to write to /usr/local/bin.
	file, _ := ioutil.TempFile("", "juju-run")
	defer file.Close()
	s.PatchValue(&agentcmd.JujuRun, file.Name())
}

func (s *dblogSuite) TestMachineAgentLogsGoToDB(c *gc.C) {
	s.SetFeatureFlags("db-log")
	foundLogs := s.runMachineAgentTest(c)
	c.Assert(foundLogs, jc.IsTrue)
}

func (s *dblogSuite) TestMachineAgentLogsGoToDBWithJES(c *gc.C) {
	s.SetFeatureFlags(feature.JES)
	foundLogs := s.runMachineAgentTest(c)
	c.Assert(foundLogs, jc.IsTrue)
}

func (s *dblogSuite) TestMachineAgentWithoutFeatureFlag(c *gc.C) {
	s.SetFeatureFlags()
	foundLogs := s.runMachineAgentTest(c)
	c.Assert(foundLogs, jc.IsFalse)
}<commit_msg>Skip changing password during test<commit_after>// Copyright 2015 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.

package featuretests

import (
	"bufio"
	"io/ioutil"
	"time"

	"github.com/juju/loggo"
	"github.com/juju/names"
	jujutesting "github.com/juju/testing"
	jc "github.com/juju/testing/checkers"
	gc "gopkg.in/check.v1"
	"gopkg.in/mgo.v2/bson"

	"github.com/juju/juju/agent"
	"github.com/juju/juju/api"
	agentcmd "github.com/juju/juju/cmd/jujud/agent"
	agenttesting "github.com/juju/juju/cmd/jujud/agent/testing"
	"github.com/juju/juju/cmd/jujud/util/password"
	"github.com/juju/juju/feature"
	"github.com/juju/juju/lease"
	"github.com/juju/juju/state"
	coretesting "github.com/juju/juju/testing"
	"github.com/juju/juju/testing/factory"
	"github.com/juju/juju/version"
	"github.com/juju/juju/worker/logsender"
	"github.com/juju/juju/worker/peergrouper"
)

// dblogSuite tests that logs flow correctly from the machine and unit
// agents over the API into MongoDB. These are very much integration
// tests with more detailed testing of the individual components
// being done in unit tests.
type dblogSuite struct {
	agenttesting.AgentSuite
}

func (s *dblogSuite) SetUpTest(c *gc.C) {
	s.SetInitialFeatureFlags("db-log")
	s.AgentSuite.SetUpTest(c)
	s.PatchValue(&password.EnsureJujudPassword, func() error { return nil })

	// Change the path to "juju-run", so that the
	// tests don't try to write to /usr/local/bin.
	file, _ := ioutil.TempFile("", "juju-run")
	defer file.Close()
	s.PatchValue(&agentcmd.JujuRun, file.Name())
}

func (s *dblogSuite) TestMachineAgentLogsGoToDB(c *gc.C) {
	s.SetFeatureFlags("db-log")
	foundLogs := s.runMachineAgentTest(c)
	c.Assert(foundLogs, jc.IsTrue)
}

func (s *dblogSuite) TestMachineAgentLogsGoToDBWithJES(c *gc.C) {
	s.SetFeatureFlags(feature.JES)
	foundLogs := s.runMachineAgentTest(c)
	c.Assert(foundLogs, jc.IsTrue)
}

func (s *dblogSuite) TestMachineAgentWithoutFeatureFlag(c *gc.C) {
	s.SetFeatureFlags()
	foundLogs := s.runMachineAgentTest(c)
	c.Assert(foundLogs, jc.IsFalse)
}
{'fraction_non_alphanumeric': 0.1404169806581261, 'fraction_numerical': 0.0035167043456417984, 'mean_word_length': 4.57703081232493, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1651967', 'n_tokens_mistral': 1673, 'n_tokens_neox': 1580, 'n_words': 296}